package com.hd.sup.modules.vehicle.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

/**
 * <p>
 * 车辆末次信息表 | 看看pg有没有内存表
 * </p>
 *
 * @author chentl123
 * @since 2020-12-28
 */
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("sp_vehicle_end_pos")
public class VehicleEndPos extends Model<VehicleEndPos> implements Serializable {

    private static final long serialVersionUID = 1L;

    //GPS坐标查询构造
    public VehicleEndPos(String regionCode, Integer length) {
        this.regionCode = regionCode;
        this.length = length;
    }


    //实时监测查询构造
    public VehicleEndPos(String platNo, String platNoColor, String enterpriseNo) {
        this.platNo = platNo;
        this.platNoColor = platNoColor;
        this.enterpriseNo = enterpriseNo;
    }

    /**
     * 末次信息id
     */
    private String id;
    /**
     * 车辆状态 |  整数存二进制  aac 开、aac关等..
     */
    @TableField("vehicle_status")
    private Long vehicleStatus;
    /**
     * 经度
     */
    private Double lng;
    /**
     * 维度
     */
    private Double lat;
    /**
     * 速度
     */
    private Double speed;
    /**
     * 高度
     */
    private Double alt;
    /**
     * GPS时间
     */
    @TableField("gps_time")
    private Date gpsTime;
    /**
     * 创建时间
     */
    @TableField("create_time")
    private Date createTime;
    /**
     * 方向
     */
    private Double direction;
    /**
     * 报警类型 | 整数存二进制
     */
    @TableField("alarm_type")
    private Long alarmType;
    /**
     * 附加信息
     */
    @TableField("info_ex")
    private String infoEx;
    /**
     * 行车记录仪速度
     */
    @TableField("add_speed")
    private Double addSpeed;
    /**
     * 车牌号
     */
    @TableField("plat_no")
    private String platNo;
    /**
     * 车牌颜色
     */
    @TableField("plat_no_color")
    private String platNoColor;
    /**
     * 连续驾驶开始时间
     */
    @TableField("continuous_driving_start_time")
    private Date continuousDrivingStartTime;
    /**
     * 数据更新时间
     */
    @TableField("update_time")
    private Date updateTime;
    /**
     * 停车时间
     */
    @TableField("parking_time")
    private Date parkingTime;
    /**
     * 连续驾驶时长
     */
    @TableField("driving_duration")
    private String drivingDuration;
    /**
     * 驾驶员姓名
     */
    @TableField("driver_name")
    private String driverName;
    /**
     * 车辆上线状态
     */
    @TableField("online_status")
    private Integer onlineStatus;
    /**
     * 静态数据同步状态 | 0 未同步 1 已同步
     */
    @TableField("static_data_status")
    private Integer staticDataStatus;
    /**
     * 同步描述
     */
    @TableField("sync_remark")
    private String syncRemark;
    /**
     * 组织机构id
     */
    @TableField("dept_id")
    private String deptId;
    /**
     * 企业编号
     */
    @JSONField(name = "enterpriseNo")
    @TableField("enterprise_no")
    private String enterpriseNo;
    /**
     * 最后登录时间
     */
    @JSONField(name = "loginTime")
    @TableField("last_login_time")
    private Date lastLoginTime;
    /**
     * 最后登出时间
     */
    @JSONField(name = "logoutTime")
    @TableField("last_logout_time")
    private Date lastLogoutTime;
    /**
     * 总里程
     */
    @JSONField(name = "curTotalDistance")
    @TableField("total_mileage")
    private String totalMileage;
    /**
     * 运输类型
     */
    @TableField("trans_type")
    private String transType;

    /*****持久化数据 ******/
    @TableField(exist = false)
    private String vehicleType;


    @TableField(exist = false)
    private String regionCode;

    @TableField(exist = false)
    private String regionName;

    @TableField(exist = false)
    private String enterpriseName;

    @TableField(exist = false)
    private String bizAlarmType;

    @TableField(exist = false)
    private String vehicleId;

    @TableField(exist = false)
    private Date lastGpsTime;

    @TableField(exist = false)
    private Date lastUpdateTime;

    @TableField(exist = false)
    private Double lastLng;

    @TableField(exist = false)
    private Double lastLat;

    @TableField(exist = false)
    private Integer length;

    @TableField(exist = false)
    private Date nightStartTime;

    @TableField(exist = false)
    private boolean scheduled;


    //地图视窗 左上 左下 右上 右下 经纬度
    @TableField(exist = false)
    private Double leftLng;
    @TableField(exist = false)
    private Double rightLng;
    @TableField(exist = false)
    private Double topLat;
    @TableField(exist = false)
    private Double bottomLat;
    @TableField(exist = false)
    private Integer limit;

    /**
     * @return void
     * @author chentl
     * @description 清空GPS数据
     * @date 2021/1/7 3:48 下午
     * @params []
     */
    public void clearGpsData() {
        this.gpsTime = null;
        this.lng = null;
        this.lat = null;
        this.speed = null;
        this.alt = null;
        this.direction = null;
        this.addSpeed = null;
        this.continuousDrivingStartTime = null;
        this.lastUpdateTime = null;
        this.lastLng = null;
        this.lastLat = null;
    }

    /**
     * @return void
     * @author chentl
     * @description 清理夜间连续行驶时间
     * @date 2021/1/27 6:29 下午
     * @params []
     */
    public void clearNightStartTime() {
        this.nightStartTime = null;
    }


    /**
     * @return void
     * @author chentl
     * @description 刷新上次GPS
     * @date 2021/1/9 1:01 下午
     * @params []
     */
    public VehicleEndPos refreshLastGps() {
        this.lastGpsTime = this.gpsTime;
        this.lastUpdateTime = this.updateTime;
        this.lastLng = this.lng;
        this.lastLat = this.lat;
        return this;
    }

    @Override
    protected Serializable pkVal() {
        return this.id;
    }
}
